package com.qf.controller;

import com.qf.pojo.Guanzhu;
import com.qf.pojo.Lianhe;
import com.qf.pojo.User;
import com.qf.service.GuanZhuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/guanzhu")
public class GuanZhuController {

    @Autowired
    private GuanZhuService guanZhuService;

    //添加关注或取消关注
    @RequestMapping("/add")
    @ResponseBody
    public Boolean insertLH(Integer lid, HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        Integer id = user.getId();
        Guanzhu guanzhu = new Guanzhu();
        guanzhu.setId(id);
        guanzhu.setLid(lid);
        Boolean jieGuo = guanZhuService.selectByLidAndId(guanzhu);
        return jieGuo;
    }

    //显示关注页
    @RequestMapping("/xianshi")
    @ResponseBody
    public List<Lianhe> selectGuanZhu(HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        Integer id = user.getId();
        List<Lianhe> xsGuanZhus = guanZhuService.selectById(id);
        return xsGuanZhus;
    }
}
